﻿using AutoMapper;
using B.WMS.GoodsDto.Input;
using B.WMS.WMSEntities.GoodsEntities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus.Distributed;

namespace B.WMS.rabbitmq.Create
{
    public class CreateGoodsHandler : IDistributedEventHandler<CreateGoodsInput>, ITransientDependency
    {
        private readonly IMapper mapper;
        private readonly IRepository<Goods,Guid> goodsRepository;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mapper"></param>
        /// <param name="goodsRepository"></param>
        public CreateGoodsHandler(IMapper mapper, IRepository<Goods, Guid> goodsRepository)
        {
            this.mapper = mapper;
            this.goodsRepository = goodsRepository;
        }
        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="eventData"></param>
        /// <returns></returns>
        public Task HandleEventAsync(CreateGoodsInput eventData)
        {
            var goods= mapper.Map<CreateGoodsInput, Goods>(eventData);
            goods.Goodscoding = AutoCode.AutoCode.GetCode("Gd").Result.ResultData;
            return goodsRepository.InsertAsync(goods);
        }
    }

}
